package org.jetlinks.community.auth.dimension;

import org.hswebframework.ezorm.rdb.mapping.ReactiveRepository;
import org.hswebframework.web.authorization.Dimension;
import org.hswebframework.web.authorization.DimensionType;
import org.hswebframework.web.authorization.simple.SimpleDimension;
import org.hswebframework.web.system.authorization.defaults.service.DefaultDimensionUserService;
import org.hswebframework.web.system.authorization.defaults.service.terms.DimensionTerm;
import org.jetlinks.community.auth.entity.OrganizationEntity;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

@Component
public class TenantDimensionProvider extends BaseDimensionProvider<OrganizationEntity> {

    public TenantDimensionProvider(ReactiveRepository<OrganizationEntity, String> repository,
                                         DefaultDimensionUserService dimensionUserService,
                                         ApplicationEventPublisher eventPublisher) {
        super(repository, eventPublisher, dimensionUserService);
    }

    @Override
    protected DimensionType getDimensionType() {
        return OrgDimensionType.tenant;
    }

    @Override
    protected Mono<Dimension> convertToDimension(OrganizationEntity entity) {
        Map<String, Object> options = new HashMap<>();
        options.put("path", entity.getPath());
        return Mono.just(SimpleDimension.of(entity.getId(), entity.getName(), getDimensionType(), options));
    }

}
